home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ELYVER10.ZIP / MIKXMAS.ZIP / source / mikwav.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  2.6 KB  |  139 lines

  1. /*
  2.  
  3. Name:
  4. MIKWAV.C
  5.  
  6. Description:
  7. WAV playing example source.
  8.  
  9. Portability:
  10.  
  11. MSDOS:    BC(y)    Watcom(y)    DJGPP(?)
  12. Win95:    BC(n)
  13. Linux:    n
  14.  
  15. (y) - yes
  16. (n) - no (not possible or not useful)
  17. (?) - may be possible, but not tested
  18.  
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23. #include <dos.h>
  24. #include "mikmod.h"
  25.  
  26.  
  27. void InitWasOkay(void)
  28. {
  29.     int t;
  30.     SAMPLE *s1,*s2;
  31.  
  32.     if((s1=MW_LoadWavFN("b1.wav"))==NULL){
  33.         printf("Wavload error: %s.\n",myerr);
  34.         return;
  35.     }
  36.  
  37.     if((s2=MW_LoadWavFN("b2.wav"))==NULL){
  38.         printf("Wavload error: %s.\n",myerr);
  39.         MW_FreeWav(s1);
  40.         return;
  41.     }
  42.  
  43.     md_numchn=4;
  44.  
  45.     MD_PlayStart();
  46.  
  47.     puts("Press key 1,2,3,4 to play the wav files, press 'q' to quit.");
  48.  
  49.     while(1){
  50.  
  51.         t=kbhit() ? getch() : 0;
  52.  
  53.         if(t=='q') break;
  54.  
  55.         if(t=='1'){
  56.             MD_VoiceSetVolume(0,64);
  57.             MD_VoiceSetPanning(0,0);
  58.             MD_VoiceSetFrequency(0,12000);
  59.             MD_VoicePlay(0,s1->handle,0,s1->length,0,0,s1->flags);
  60.         }
  61.  
  62.         if(t=='2'){
  63.             MD_VoiceSetVolume(1,64);
  64.             MD_VoiceSetPanning(1,64);
  65.             MD_VoiceSetFrequency(1,13000);
  66.             MD_VoicePlay(1,s1->handle,0,s1->length,0,0,s1->flags);
  67.         }
  68.  
  69.         if(t=='3'){
  70.             MD_VoiceSetVolume(2,64);
  71.             MD_VoiceSetPanning(2,128);
  72.             MD_VoiceSetFrequency(2,10000);
  73.             MD_VoicePlay(2,s2->handle,0,s2->length,0,0,s2->flags);
  74.         }
  75.  
  76.         if(t=='4'){
  77.             MD_VoiceSetVolume(3,64);
  78.             MD_VoiceSetPanning(3,200);
  79.             MD_VoiceSetFrequency(3,12000);
  80.             MD_VoicePlay(3,s2->handle,0,s2->length,0,0,s2->flags);
  81.         }
  82.  
  83.         delay(10);
  84.         MD_Update();
  85.     }
  86.  
  87.     MD_PlayStop();
  88.     MW_FreeWav(s1);
  89.     MW_FreeWav(s2);
  90. }
  91.  
  92.  
  93. int main(int argc,char *argv[])
  94. {
  95.     puts(mikbanner);
  96.  
  97.     /*
  98.         Initialize soundcard parameters.. you _have_ to do this
  99.         before calling MD_Init(), and it's illegal to change them
  100.         after you've called MD_Init()
  101.     */
  102.  
  103.     md_mixfreq              =44100;                         /* standard mixing freq */
  104.     md_dmabufsize           =8000;                          /* standard dma buf size */
  105.     md_mode                 =DMODE_16BITS|DMODE_STEREO;             /* standard mixing mode */
  106.     md_device               =0;                                     /* standard device: autodetect */
  107.  
  108.     /*
  109.         Register the drivers we want to use:
  110.     */
  111.  
  112.     MD_RegisterDriver(&drv_ss);
  113.     MD_RegisterDriver(&drv_sb);
  114.     MD_RegisterDriver(&drv_gus);
  115.  
  116.     /*      initialize soundcard */
  117.  
  118.     if(!MD_Init()){
  119.         printf("Driver error: %s.\n",myerr);
  120.         return 0;
  121.     }
  122.  
  123.     printf("Using %s for %d bit %s sound at %u Hz\n\n",
  124.             md_driver->Name,
  125.             (md_mode&DMODE_16BITS) ? 16:8,
  126.             (md_mode&DMODE_STEREO) ? "stereo":"mono",
  127.             md_mixfreq);
  128.  
  129.     /* call main program */
  130.  
  131.     InitWasOkay();
  132.  
  133.     /* and clean up */
  134.  
  135.     MD_Exit();
  136.     return 0;
  137. }
  138.  
  139.